#!/bin/bash

# 定义变量
LOCAL_BUILD_DIR="dist"
REMOTE_USER="anxincat"
REMOTE_HOST="anxincat.top"
REMOTE_PORT="2222"
REMOTE_DIR="~/blog/"


# 构建项目
echo "Building the Astro project..."
npm run build

# 检查构建是否成功
if [ $? -ne 0 ]; then
    echo "Build failed. Exiting."
    exit 1
fi

# 上传构建的文件到远程服务器
echo "Uploading files to remote server..."
scp -P $REMOTE_PORT -r $LOCAL_BUILD_DIR/* $REMOTE_USER@$REMOTE_HOST:$REMOTE_DIR

# 检查上传是否成功
if [ $? -ne 0 ]; then
    echo "File upload failed. Exiting."
    exit 1
fi

echo "Files successfully uploaded to $REMOTE_HOST:$REMOTE_DIR"

# 结束
exit 0